using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameVuTru.ManagerScreens;
using GameVuTru.GameObject;
namespace GameVuTru.Screens
{
    class WinScreen : GameScreen
    {

        #region Fields

        ContentManager content;
        BackGround bg;
        CSprite  Spritepl;
        Vector2 posSprite;
        float time;
        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public WinScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
            time = 0;
            GameplayScreen.boomIsexplosioned = false;
            posSprite = new Vector2(GameplayScreen.PosSprite.X, 380);

        }


        /// <summary>
        /// Loads graphics content for this screen. The background texture is quite
        /// big, so we use our own local ContentManager to load it. This allows us
        /// to unload before going from the menus into the game itself, wheras if we
        /// used the shared ContentManager provided by the Game class, the content
        /// would remain loaded forever.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            // CreateLevel.level++;
            bg = new BackGround(ResourceManager.ReSouce.background, 20);
            Spritepl = new CSprite(ResourceManager.ReSouce.phithuyen, 3, 3, 180, 60);
           
        }


        /// <summary>
        /// Unloads graphics content for this screen.
        /// </summary>
        public override void UnloadContent()
        {
            content.Unload();
        }


        #endregion

        #region Update and Draw


        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            //  ScreenManager.AddScreen(new GameplayScreen(),null);
            bg.Update(gameTime);
            Spritepl.UpdateSprite(gameTime, 0, 2, 1);
            time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            posSprite.Y -= 2.8f;
            if (time >= 5000)
            {
                CreateLevel.level++;
                ScreenManager.RemoveScreen(this);
                ScreenManager.AddScreen(new GameplayScreen(), null);
            }

        }


        /// <summary>
        /// Draws the background screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);

            spriteBatch.Begin();
            bg.Draw(spriteBatch);
            Spritepl.DrawSprite(spriteBatch, posSprite);
            spriteBatch.DrawString(ScreenManager.Font, "LEVEL " + (CreateLevel.level + 1).ToString(), new Vector2(300, 200), Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f);

            spriteBatch.End();
        }


        #endregion
    }

}
